php how to convert string to int

95

php how to convert string to int -

$num = intval("10");
$num = floatval("10.1");

convert to int php -

$myintvariable = intval($myvariable);

Convert a String to a Number in PHP -

phpCopy<?php  
$variable = "10";
$integer = (int)$variable;
echo "The variable $variable has converted to a number and its value is $integer.";  
echo "\n";

$variable = "8.1";
$float = (float)$variable;
echo "The variable $variable has converted to a number and its value is $float.";  
?>

string to int php -

$str = "10";
$num = (int)$str;

Convert a String to a Number in PHP -

phpCopy<?php  
$variable = "45";
settype($variable, "integer");
echo "The variable has converted to a number and its value is $variable.";  
?>

Comments

Submit
0 Comments